{{define "content"}}

{{template "breadcrumbs" .}}

<div class="container">
  <div class="row mb-3">

    <div class="col-sm-6 border-end">
      <h4 class="mb-3">Packages</h4>
      {{ if .Missing}}
        <p class="mb-3">No such package or prefix</p>
      {{else}}
        <table class="table table-striped table-sm">
        {{range $item := .Listing}}
          <tr>
            <td>
              {{if $item.Active}}
                <b>
                  {{if $item.Package}}{{template "package-icon" .}}{{end}}
                  {{$item.Title}}
                </b>
                {{if $.Instances}}
                  <a href="#instances" class="float-end me-2">{{template "arrow-down-icon" .}}</a>
                {{end}}
              {{else}}
                <a href="{{$item.Href}}">
                {{if $item.Package}}{{template "package-icon" .}}{{end}}
                {{if $item.Back}}
                  &#8617;
                {{else if $item.Prefix}}
                  {{$item.Title}}/&#8230;
                {{else}}
                  {{$item.Title}}
                {{end}}
              {{end}}
              </a>
            </td>
          </tr>
        {{end}}
        </table>
      {{end}}
    </div>

    <div class="col-sm-6">
      <h4 class="mb-3">ACLs</h4>
      {{if not .Metadata.CanView}}

        {{if .IsAnonymous}}
        <p>Please <a href="{{.LoginURL}}">login</a> to view more.</p>
        {{else}}
        <p>Your roles in the prefix are:</p>
          {{if .Metadata.CallerRoles}}
          <ul>
            {{range $role := .Metadata.CallerRoles}}
            <li>{{.}}</li>
            {{end}}
          </ul>
          {{else}}
          <p>None</p>
          {{end}}
        <p>To view all ACLs you must be an owner.</p>
        {{end}}

      {{else}}

      <table class="table table-striped table-sm">
      {{range $acl := .Metadata.ACLs}}
        <tr>
          <td class="info-table-key">{{.Role}}</td>
          <td>
            {{if .WhoHref}}
              <a href="{{.WhoHref}}" target="_blank">
                {{.Who}} {{if .Missing}}{{template "missing-group-icon" .}}{{end}}
              </a>
            {{else}}
              {{.Who}} {{if .Missing}}{{template "missing-group-icon" .}}{{end}}
            {{end}}
            via <a href="{{.PrefixHref}}">{{.Prefix}}</a>
          </td>
        </tr>
      {{end}}
      </table>

      {{end}}
    </div>

  </div>


  {{if .Instances}}
  <div class="row mt-4">
    <div class="col-sm-12 border-top pt-4">
      <a name="instances"></a>
      <h3 class="user-select-all font-monospace text-center mb-3">{{.Package}}</h3>
    </div>
  </div>

  <div class="row mt-2">

    <div class="col-sm-6 border-end">
      <h4 class="mb-3">Instances</h4>
      <div class="table-responsive">
        <table class="table table-striped table-sm">
        {{if .PrevPageURL}}
          <tr>
            <td><a href="{{.PrevPageURL}}">...</a></td>
            <td></td>
          </tr>
        {{end}}
        {{range $item := .Instances}}
          <tr>
            <td class="age-td">{{.Age}}</td>
            <td style="white-space: nowrap;">
              <a class="version-link" href="{{.Href}}" title="{{.ID}}">
                {{.TruncatedID}}&hellip;
              </a>
              {{range $ref := .Refs}}
                <a class="btn btn-secondary ref-btn" href="{{.Href}}"
                   title="Set by {{.User}} {{.Age}} ago">
                  {{.Title}}
                </a>
              {{end}}
            </td>
          </tr>
        {{end}}
        {{if .NextPageURL}}
          <tr>
            <td><a href="{{.NextPageURL}}">...</a></td>
            <td></td>
          </tr>
        {{end}}
        </table>
      </div>
    </div>

    <div class="col-sm-6">
      {{template "refs-table" .Refs}}
    </div>
  </div>
  {{end}}

</div>


{{end}}
